<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="jsonA">下载json</button>
</body>
<script>
    const button = document.getElementById("jsonA") 
    const download = async()=>{
        try {
            const fileName = "data.json";
            const res = await fetch("./"+fileName);
            const blob = await res.blob();
            const url = URL.createObjectURL(blob);
            const alink = document.createElement("a");
            alink.href = url;
            alink.download = fileName;
            alink.click();
            URL.revokeObjectURL(url);
        } catch (error) {
            console.log(error);
        }
    }
    button.addEventListener("click",download)
</script>
</html>